import service from '@/utils/request'





/**
 * 下载Minio中的文件
 * @param {string} fileName - 文件名
 * @param {boolean} [delete=false] - 是否在下载后删除文件
 */
export function downloadMinioFile(fileName) {
  const url = '/common/downloadMinio';
  const params = { fileName };


  return service.get(url, {
    params: params,
    // headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    responseType: 'blob', // 确保响应类型为blob以便处理文件下载
  }).then(async (response) => {


    // 处理返回的Blob文件流
    const blob = new Blob([response], {
      type: "application/octet-stream;chartset=UTF-8"
    });
    saveAs(blob, fileName);
  });
}

export function previewFile(fileName) {
  return service({
    url: '/common/preview/',
    method: 'get',
    params: { fileName: fileName } // 自动编码
  })
}
